<template>
	<div>
		<!-- 完成提货弹窗 -->
		<uni-popup ref="completePickDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定开始" title="确定开始提货"
				@confirm="completePickDialogConfirm" :before-close="true" @close="closeDialog('completePickDialog')">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 120px;">
					<!-- <uni-forms ref="form_pickup" :modelValue="formData_pickup" :rules="rules_pickup" labelWidth="75px">
						<uni-forms-item label="提货人" name="pickupName" required>
							<uni-easyinput type="text" v-model="formData_pickup.pickupName" placeholder="请输入提货人" />
						</uni-forms-item>
						<uni-forms-item label="联系电话" name="contactPhone" required>
							<uni-easyinput type="number" v-model="formData_pickup.contactPhone" placeholder="请输入联系电话" />
						</uni-forms-item>
						<uni-forms-item label="提货费" name="amount">
							<uni-easyinput type="text" v-model="formData_pickup.amount" placeholder="请输入提货费" />
						</uni-forms-item>
						<uni-forms-item label="车牌号" name="plateNumber" required>
							<uni-combox  :candidates="plateNumber" placeholder="请输入车牌号"
								v-model="formData_pickup.plateNumber"></uni-combox>
						</uni-forms-item>
						<uni-forms-item label="计费方式" name="feeMode">
							<uni-data-select v-model="formData_pickup.feeMode" :localdata="feeMode"
								style="background-color: white;" />
						</uni-forms-item>
						<uni-forms-item label="备注">
							<uni-easyinput type="textarea" v-model="formData_pickup.remark" placeholder="提货相关备注说明" />
						</uni-forms-item>
					</uni-forms>
					<view style="height: 50px;"></view> -->
					<view style="display: flex;flex-direction: column;width: 100%;">
						<view style="display: flex;">
							<text style="width: 75px;">发车批次：</text>
							<text style="font-weight: bold;margin-left: 20px;">{{formData.scheduleVo.scheduleNo}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">承运方：</text>
							<text style="margin-left: 20px;">{{formData.scheduleVo.carrierVo?formData.scheduleVo.carrierVo.carrierName:'无'}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">车型：</text>
							<text style="margin-left: 20px;">{{carType_[formData.scheduleVo.carVo.carType]}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">车牌号：</text>
							<text style="margin-left: 20px;">{{formData.scheduleVo.carVo.licensePlate}}</text>
						</view>
						<!-- <view style="display: flex;">
							<text style="width: 75px;">车辆定位：</text>
							<text style="margin-left: 20px;">{{formData.scheduleVo.scheduleNo}}</text>
						</view> -->
						<view style="display: flex;">
							<text style="width: 75px;">司机：</text>
							<text style="margin-left: 20px;">{{formData.scheduleVo.driverVo.driverName}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">司机电话：</text>
							<text style="margin-left: 20px;">{{formData.scheduleVo.driverVo.phoneNumber}}</text>
						</view>
						<view style="height: 50px;"></view>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 取消提货提示窗 -->
		<uni-popup ref="cancelPickDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认" title="取消提货运单"
				@confirm="cancelPickDialogConfirm">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 160px;">
					<!-- <view style="display: flex;flex-direction: column;width: 100%;">
						<view style="display: flex;">
							<text style="width: 75px;">提货人：</text>
							<text style="font-weight: bold;margin-left: 20px;">{{formData_pickup.pickupName}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">详细电话：</text>
							<text style="margin-left: 20px;">{{formData_pickup.contactPhone}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">计费方式：</text>
							<text style="margin-left: 20px;">{{formData_pickup.feeMode}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">提货费(元)：</text>
							<text style="margin-left: 20px;">{{formData_pickup.amount}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">车牌号：</text>
							<text style="margin-left: 20px;">{{formData_pickup.plateNumber}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">备注：</text>
							<text style="margin-left: 20px;">{{formData_pickup.remark}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">操作人：</text>
							<text style="margin-left: 20px;">{{formData_pickup.createBy}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">操作时间：</text>
							<text style="margin-left: 20px;">{{formData_pickup.updateTime}}</text>
						</view>
						<view style="display: flex;margin-top: 10px;color: #bf5f09;">
							<text>*确认取消当前提货</text>
						</view>
					</view> -->
					<view style="display: flex;flex-direction: column;width: 100%;">
							<view style="display: flex;">
								<text style="width: 75px;">发车批次：</text>
								<text style="font-weight: bold;margin-left: 20px;">{{formData.scheduleVo.scheduleNo}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">承运方：</text>
								<text style="margin-left: 20px;">{{formData.scheduleVo.carrierVo?formData.scheduleVo.carrierVo.carrierName:'无'}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">车型：</text>
								<text style="margin-left: 20px;">{{carType_[formData.scheduleVo.carVo.carType]}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">车牌号：</text>
								<text style="margin-left: 20px;">{{formData.scheduleVo.carVo.licensePlate}}</text>
							</view>
							<!-- <view style="display: flex;">
								<text style="width: 75px;">车辆定位：</text>
								<text style="margin-left: 20px;">{{formData.scheduleVo.scheduleNo}}</text>
							</view> -->
							<view style="display: flex;">
								<text style="width: 75px;">司机：</text>
								<text style="margin-left: 20px;">{{formData.scheduleVo.driverVo.driverName}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">司机电话：</text>
								<text style="margin-left: 20px;">{{formData.scheduleVo.driverVo.phoneNumber}}</text>
							</view>
							<view style="display: flex;margin-top: 10px;color: #bf5f09;">
								<text>*确认取消当前提货</text>
							</view>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script>
	import {
		updateWayBillPickup,
	} from '@/api/system/waybill.js'
	import {getCarrierCarList} from '@/api/system/driver.js'
	import {getDicts} from '@/api/system/dict.js'
	
	export default {
		props: {
			data: {
				type: Object,
				default: {}
			},
			data_pickup: {
				type: Object,
				default: {}
			},
			waybillId:{
				type: String,
				default:''
			},
			carType_:{
				type: Array,
				default:[]
			},
		},
		data() {
			return {
				formData:{},
				//提货
				formData_pickup: {
					pickupName:'',
					contactPhone:'',
					amount:'',
					plateNumber:'',
					feeMode:'',
					remark:'',
					
					flowStatus:'',
					waybillId:''
				},
				// 校验规则->提货
				rules_pickup: {
					pickupName: {
						rules: [{
							required: true,
							errorMessage: '请输入提货人',
						}]
					},
					contactPhone: {
						rules: [{
							required: true,
							errorMessage: '请输入联系电话',
						},
						{
						    pattern: '^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$',
						    errorMessage: '电话格式不正确'
						}
						]
					},
					plateNumber: {
						rules: [{
							required: true,
							errorMessage: '请输入车牌号',
						}]
					}
				},
				//下拉框->车牌号
				plateNumber:[],
				//计费方式->下拉框
				feeMode:[],
			}
		},
		watch: {
			data: {
			　　handler(newValue, oldValue) {
			　　　	this.formData=newValue
			　　},
			　	deep: true,
				immediate:true
			},
			data_pickup: {
			　　handler(newValue, oldValue) {
			　　　	this.formData_pickup=newValue
			　　},
			　	deep: true,
				immediate:true
			},
		},
		created() {
			//加载计费方式
			getDicts('price_method').then(res=>{
				this.feeMode=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
		},
		methods: {
			//关闭弹窗
			closeDialog(name){
				this.$refs[name].close()
			},
			//完成提货
			completePick(){
				//获取车牌号下拉框
				getCarrierCarList({pageNum:1,pageSize:1000}).then(res=>{
					this.plateNumber=res.rows.map(item=>{
						return item.licensePlate
					})
				})
				
				this.$refs.completePickDialog.open()
			},
			//确认完成提货
			completePickDialogConfirm() {
				uni.showLoading({
					title: '正在提货...',
				})
				//提货完成
				this.formData_pickup.waybillId=this.waybillId;
				this.formData_pickup.flowStatus='120';
				updateWayBillPickup(this.formData_pickup).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						uni.showToast({
							title: '提货成功',
							icon: 'none'
						})
						
						this.$refs.completePickDialog.close()
						this.$parent.init()  //调用父组件的init函数
						//this.$forceUpdate(); //重新加载数据
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}	
				})
				// this.$refs.form_pickup.validate().then(res => {
				// 	uni.showLoading({
				// 		title: '正在提货...',
				// 	})
				// 	//提货完成
				// 	this.formData_pickup.waybillId=this.waybillId;
				// 	this.formData_pickup.flowStatus='120';
				// 	updateWayBillPickup(this.formData_pickup).then(res => {
				// 		uni.hideLoading()
				// 		if (res.code == '200') {
				// 			uni.showToast({
				// 				title: '提货成功',
				// 				icon: 'none'
				// 			})
							
				// 			this.$refs.completePickDialog.close()
				// 			this.$parent.init()  //调用父组件的init函数
				// 			//this.$forceUpdate(); //重新加载数据
				// 		} else {
				// 			uni.showToast({
				// 				icon: 'none',
				// 				title: res.msg
				// 			})
				// 		}	
				// 	})
				// }).catch(err => {
				// 	uni.showToast({
				// 		title: err[0].errorMessage,
				// 		icon: 'none'
				// 	})
				// })
			},
			//取消提货
			canclePick(){
				this.$refs.cancelPickDialog.open()
			},
			//确认取消提货
			cancelPickDialogConfirm(){
				uni.showLoading({
					title: '正在取消提货...',
				})
				//取消提货完成
				this.formData_pickup.waybillId=this.waybillId;
				this.formData_pickup.flowStatus='111';
				updateWayBillPickup(this.formData_pickup).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						uni.showToast({
							title: '取消提货成功',
							icon: 'none'
						})
						this.$parent.init()  //调用父组件的init函数，重新加载数据
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}		
				})
			},
		},
	}
</script>

<style scoped>

</style>